/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Panel_TaskToProject.java
 *
 * Created on Apr 23, 2011, 6:06:46 PM
 */

package contextswitch_swing;

import com.pew.tasktimer.domain.Task;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import org.apache.log4j.Logger;

/**
 *
 * @author Elwin
 */
public class Panel_TaskToProject extends javax.swing.JPanel {

    private static Logger cLogger = Logger.getLogger(TaskGUI.class);

    private static String cStrDateFormat = "MM/dd/yyyy HH:mm:ss";

    private static long clEpoch = 18000000;
    private static long clMilDay = 86400000;

    private static SimpleDateFormat lSDFDate = new SimpleDateFormat(cStrDateFormat);
    
    private static DecimalFormat cNF = new DecimalFormat("#.####");

    private Task cTask = null;
    private boolean isDirty = false;

    /** Creates new form Panel_TaskToProject */
    public Panel_TaskToProject() {
        initComponents();
    }

    public Panel_TaskToProject(Task myTask) {
        this();
        loadTask(myTask);
    }

    public void loadTask(Task myTask){
        cTask = myTask;

        if (cLogger.isDebugEnabled()) {
            cLogger.debug("Loading Task into GUI: " + myTask.toString());
        }
        Calendar lCal = Calendar.getInstance();


        lCal.setTimeInMillis(myTask.getClStartTime());

        startDT.setText(lSDFDate.format(lCal.getTime()));

        lCal.setTimeInMillis(myTask.getClStopTime());
        stopDT.setText(lSDFDate.format(lCal.getTime()));

        noteStr.setText(cTask.getNote());
        jlTotal.setText(cNF.format(myTask.getCfDiffHourF()) + "");
    }



    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        startDT = new javax.swing.JLabel();
        stopDT = new javax.swing.JLabel();
        noteStr = new javax.swing.JTextField();
        jlTotal = new javax.swing.JLabel();

        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(contextswitch_swing.ContextSwitch_SwingApp.class).getContext().getResourceMap(Panel_TaskToProject.class);
        startDT.setText(resourceMap.getString("startDT.text")); // NOI18N
        startDT.setName("startDT"); // NOI18N

        stopDT.setText(resourceMap.getString("stopDT.text")); // NOI18N
        stopDT.setName("stopDT"); // NOI18N

        noteStr.setEditable(false);
        noteStr.setText(resourceMap.getString("noteStr.text")); // NOI18N
        noteStr.setName("noteStr"); // NOI18N

        jlTotal.setText(resourceMap.getString("jlTotal.text")); // NOI18N
        jlTotal.setName("jlTotal"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(startDT, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(stopDT, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jlTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(noteStr, javax.swing.GroupLayout.PREFERRED_SIZE, 189, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(startDT)
                .addComponent(stopDT)
                .addComponent(noteStr, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jlTotal))
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jlTotal;
    private javax.swing.JTextField noteStr;
    private javax.swing.JLabel startDT;
    private javax.swing.JLabel stopDT;
    // End of variables declaration//GEN-END:variables

}
